/**
 * 
 */
package com.ly.mpayment.persist.common;

import java.io.Serializable;
import java.util.Date;

import org.hibernate.EmptyInterceptor;
import org.hibernate.type.Type;
import org.springframework.stereotype.Component;

/**
 * 
 * @版本   1.0
 * @类描述  进行实体的属性拦截
 * @创建时间 2013-6-29上午10:27:31
 */
@Component
public class EntityInterceptor extends EmptyInterceptor{

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -7099153166907537699L;

	private static final String CREATE_DATE = "createtime";
	
//	private static final String UPDATE_DATE = "updateDate";
	
	//private static final String START_DATE = "startDate";
	private static final String sendtime = "sendtime";
	
	private static final String lastlogintime = "lastlogintime";
	
	private static final String operationtime = "operationtime";
	
	private static final String backtime = "backtime";
	
	private static final String offertime = "offertime";
	
	private static final String collecttime = "collecttime";
	
	private static final String alarmtime = "alarmtime";
	
	private static final String logintime = "logintime";
	
	private static final String createTime = "createTime";
	
	
	
	
	@Override
	public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
		
		Date date = new Date();
		for(int i=0 ;i<propertyNames.length;i++){
			if(CREATE_DATE.equals(propertyNames[i]) || sendtime.equals(propertyNames[i])
					|| lastlogintime.equals(propertyNames[i])
					|| operationtime.equals(propertyNames[i])
					|| backtime.equals(propertyNames[i])
					|| offertime.equals(propertyNames[i])
					|| collecttime.equals(propertyNames[i])
					|| alarmtime.equals(propertyNames[i])
					|| logintime.equals(propertyNames[i])
					|| createTime.equals(propertyNames[i])){//||UPDATE_DATE.equals(propertyNames[i])
				state[i]=date;
			}
		}
		return true;
	}
	
	
	@SuppressWarnings("unused")
	@Override
	public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,String[] propertyNames, Type[] types) {
		Date updateDate = new Date();
		for (int i = 0; i < propertyNames.length; i++) {
			//if (UPDATE_DATE.equals(propertyNames[i])) {
			//	currentState[i] = updateDate;
		//	}
		}
		return true;
	}
}
